package com.ttai.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.ttai.R;
import com.ttai.model.dao.bean.Acount_Item;
import com.ttai.ui.activity.UaP_Protect;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

public class UapRecycleViewAdapter extends RecyclerView.Adapter {

    private Context context;
    private UaP_Protect uaP_protect;
    private ArrayList<Acount_Item> acountList = new ArrayList<Acount_Item>();
    private String acountName = "";
    private String imgUrl = "";

    public UapRecycleViewAdapter(Context context, UaP_Protect uaP_protect) {
        this.context = context;
        this.uaP_protect = uaP_protect;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_acount, null);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        acountName = acountList.get(position).getAcount_name();
        imgUrl = acountList.get(position).getImgUrl();
        Picasso.with(context).load(imgUrl).placeholder(R.drawable.taisecuritylogosmall).resize(150,150).into(((ViewHolder) holder).ivIcon);
        ((ViewHolder) holder).tvAcountname.setText(acountName);
    }

    @Override
    public int getItemCount() {
        if (acountList != null && acountList.size() > 0) {
            return acountList.size();
        }
        return 0;
    }

    public void setData(ArrayList<Acount_Item> acountList) {
        this.acountList = acountList;
        notifyDataSetChanged();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_acountname)
        TextView tvAcountname;
        @Bind(R.id.iv_icon)
        ImageView ivIcon;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);

        }
    }
}
